package com.beadhouse.base.support.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beadhouse.base.dao.RoleMenuDao;
import com.beadhouse.base.dto.MenuListDto;
import com.beadhouse.base.service.MenuService;
import com.beadhouse.entity.MenuEntity;
import com.beadhouse.entity.RoleMenuEntity;
@Service
public class MenuServiceImp implements MenuService{
	
	@Autowired
	RoleMenuDao rmd;
	@Override
	public MenuListDto getMenu(int roleId) {
		List<RoleMenuEntity> list=rmd.selectByRoleId(roleId);
		MenuListDto mld=new MenuListDto();
		List<MenuEntity> parent=new ArrayList<>();
		List<MenuEntity> child=new ArrayList<>();
		
		for(RoleMenuEntity rme:list) {
			if(rme.getMenu().getParentId()==0) {
				parent.add(rme.getMenu());
			}else {
				child.add(rme.getMenu());
			}
		}
		mld.setChild(child);
		mld.setParent(parent);
		return  mld;
	}

}
